package acwing.动态规划.线性;

import java.util.Scanner;

/**
 * 数字三角形
 *
 * @author yang
 * @date 2022/1/18
 */
public class 数字三角形 {

    static int INF = -100000000;
    static int N = 510;
    static int[][] arr = new int[N][N];

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                arr[i][j] = sc.nextInt();
            }
        }
        int[][] f = new int[N][N];
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= i + 1; j++) {
                f[i][j] = INF;
            }
        }
        f[1][1] = arr[1][1];

        for (int i = 2; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                f[i][j] = Math.max(f[i - 1][j - 1] + arr[i][j],f[i - 1][j] + arr[i][j]);
            }
        }
        int res = INF;
        for (int i = 1; i <= n; i++) res = Math.max(res, f[n][i]);
        System.out.println(res);
    }
}
